import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;

public class insertDataName {
    private static MongoClient mongoClient = null;
    private static DB db = null;
    public static void main(String[] args) throws UnknownHostException, FileNotFoundException {
        File[] files = getFiles("/Users/xiexiaohao/Desktop/PDF");
        mongoClient = new MongoClient("114.67.200.39:27817");
        db = mongoClient.getDB("Hypertension");
        DBCollection collection = db.getCollection("Guide1");

        for (File file : files) {
            String name = file.getName();
            BasicDBObject document = new BasicDBObject();
            document.put("name", name);
            collection.insert(document);
        }

    }

    public static File[] getFiles(String path) {
        //List<String> files = new ArrayList<String>();

        File file = new File(path);
        File[] tempList = file.listFiles();

        for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isFile()) {
                //tempList[i].getName();
                System.out.println(tempList[i].getName());
                //files.add(tempList[i].toString());
                //System.out.println(tempList[i].getName());
            }
        }
        return tempList;
    }
}
